package com.kaiyidiannao.adapter;

import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.kaiyidiannao.main.R;
import com.kaiyidiannao.model.bean.Auction;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by mark on 2014/4/16.
 * 我的竞价
 */
public class MyBiddingAdapter extends ImageLoaderBaseAdapter {

    private ImageLoader imageLoader;
    private LayoutInflater layoutInflater;
    private List<Auction> list = new ArrayList<Auction>();
    private String[] imgs;
    private Context context;

    public MyBiddingAdapter(Context context, List<Auction> list) {
        imageLoader = ImageLoader.getInstance();
        imageLoader.init(ImageLoaderConfiguration.createDefault(context));
        this.list = list;
        this.layoutInflater = LayoutInflater.from(context);
        this.context = context;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TextView myBiddingItemNameText = null;
        TextView myBiddingItemPriceText = null;
        TextView myBiddingInfo = null;
        TextView increaseNumber = null;
        TextView increasePeopleNum = null;
        ImageView bidding_item_ImageView = null;
        Auction auction = list.get(position);
        if (convertView==null)
        {
            convertView=layoutInflater.inflate(R.layout.mybidding_item,null);
        }
        myBiddingItemNameText = (TextView)convertView.findViewById(R.id.myBiddingItemNameText);
        myBiddingItemPriceText = (TextView)convertView.findViewById(R.id.myBiddingItemPriceText);
        myBiddingInfo = (TextView)convertView.findViewById(R.id.myBiddingInfo);
        increaseNumber = (TextView)convertView.findViewById(R.id.increaseNumber);
        increasePeopleNum = (TextView)convertView.findViewById(R.id.increasePeopleNum);
        bidding_item_ImageView = (ImageView)convertView.findViewById(R.id.bidding_item_ImageView);

//        Log.d("-=-=-=-=-=-=-=-=-","-=-=-=-=-"+list.size());
        imageLoader.displayImage(auction.getThumb(),bidding_item_ImageView, options, null);
        myBiddingItemNameText.setText(auction.getTitle());
        myBiddingItemPriceText.setText(auction.getCurrprice());
        myBiddingInfo.setText(auction.getResult());
        if (auction.getResult().contains("成功")) {
            myBiddingInfo.setTextColor(Color.GREEN);
        } else {
            myBiddingInfo.setTextColor(Color.RED);
        }
        increaseNumber.setText(auction.getCount());
        increasePeopleNum.setText(auction.getPeople() + "");

        return convertView;
    }
}
